<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        li {
            min-height: 200px;
        }
    </style>
</head>

<body>
    <h2>图片懒加载</h2>
    <ul>
        <li>
            <img class="img" alt="1.jpg" data-src="/img/1.jpg">
        </li>
        <li>
            <img class="img" alt="1.jpg" data-src="/img/2.jpg">
        </li>
        <li>
            <img class="img" alt="1.jpg" data-src="/img/3.jpg">
        </li>
        <li>
            <img class="img" alt="1.jpg" data-src="/img/4.jpg">
        </li>
        <li>
            <img class="img" alt="1.jpg" data-src="/img/5.jpg">
        </li>
        <li>
            <img class="img" alt="1.jpg" data-src="/img/1.jpg">
        </li>
        <li>
            <img class="img" alt="1.jpg" data-src="/img/1.jpg">
        </li>
    </ul>
    <script src="./js/lazyLoadImg1.js"></script>
    <script>
        lazyLoadImg('img')

        function throttle(fn) {
            clearTimeout(fn.id);
            fn.id = setTimeout(function() {
                console.log('aaaaa', fn);
                fn()
            }, 300)
        }
        document.body.onscroll = function() {
            throttle(lazyLoadImg)
        }
    </script>
</body>

</html>